package org.example.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;
/**
 * @author xietl
 * @date 2025/8/29  13:42
 * @description
 */

@Configuration
public class SessionConfig {
    @Bean
    public CookieSerializer cookieSerializer() {
        DefaultCookieSerializer serializer = new DefaultCookieSerializer();
        serializer.setCookieName("JSESSIONID");
        serializer.setCookiePath("/");
        serializer.setDomainNamePattern("^.+$"); // 允许所有域名
        serializer.setCookieMaxAge(-1); // Session cookie（浏览器关闭时删除）
        serializer.setUseSecureCookie(false); // HTTP环境下设为false
        serializer.setUseHttpOnlyCookie(true); // 保持安全性
        serializer.setSameSite("Lax"); // 改为Lax以支持跨站请求
        return serializer;
    }
}